<?php
/**
 * 管理中心· 品牌模块的逻辑处理
 * ============================================================================
 * 版权所有 2017-2020 北京优特世纪科技有限公司，并保留所有权利。
 * 网站地址: http://www.unitewww.com;
 * ============================================================================
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * @since: 1.0
 * @version: 1.0
 **/
namespace Hoteladmin\Model;
use Think\Model;
class BrandModel extends Model{
    /**
     +--------------------------------------------------------------------------
     * 实现添加或修改国家信息
     * @author:  ZJ
     * @date: 2018-09-28
     +--------------------------------------------------------------------------
     */
    public function country_add_edit($id){
        //实例化相关表
        $coident = M('country');
        $brident = M('brand');
        //接收传值
        $data['co_name'] = $cname = trim(I('post.cname'));
        $data['co_flag'] = trim(I('post.couImgUrl'));
        $data['co_sort'] = trim(I('post.sort'));
        $arr['br_country']= trim(I('post.cname'));
        $arr['br_flag']   = trim(I('post.couImgUrl'));
        $coFind = $coident->where("`co_name` = '".$cname."'")->find();
        if(count($coFind)>0){
            $res = array('status'=>-1,'msg'=>'已存在该国家信息');
			exit(json_encode($res));
        }
        //dump($id);die;
        if(''!=$id){
            $re = $coident->where("`co_id`='".$id."'")->save($data);
            $br = $brident->where("`br_coid`='".$id."'")->save($arr);
        }else{
            $re = $coident->add($data);
        }
        $re>0?$res=1:$res=0;
        return $res;
    }
    /**
     +--------------------------------------------------------------------------
     * 实现添加（修改）品牌的功能
     * @param $act 操作类型
     * @author : ZJ
     * @date : 2018-09-29
     +--------------------------------------------------------------------------
     */
    public function brandAddEdit($act){
        //实例化相关表
        $bident = M('brand');
        $cident = M('country');
        //接收传值
        $data['br_name'] = trim(I('post.bname'));
        $data['br_type']  = trim(I('post.btype'));
        $data['br_coid'] = $coid = trim(I('post.type'));
        $data['br_price']= trim(I('post.bprice'));
        $data['br_logo'] = trim(I('post.logoImgUrl'));
        $data['br_ad']   = trim(I('post.adImgUrl'));
        $data['br_cert'] = $desc = $_POST['cert'];
        $data['br_desc'] = $cert = $_POST['desc'];
        if($cert==''||$desc==''){
            $res = array('status'=>-1,'msg'=>'品牌介绍或授权书不能为空');
			exit(json_encode($res));
        }
        //利用选中国家id找出所选国家的相关信息
        $coFind = $cident->where("`co_id`='".$coid."'")->find();
        $data['br_country']= $coFind['co_name'];
        $data['br_flag']   = $coFind['co_flag'];
        if('edit'==$act){
            $re = $bident->where("`br_id`='".I('post.id')."'")->save($data);
        }else{
            $re = $bident->add($data);
        }
        $re>0?$res=1:$res=0;
        return $res;
    }
}